package com.zhaoxi.project.md.service.impl;

import java.util.List;

import com.zhaoxi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zhaoxi.project.md.mapper.MdCategoryTreeMapper;
import com.zhaoxi.project.md.domain.MdCategoryTree;

/**
 * 物料产品分类Service业务层处理
 *
 * @author zhaoxi
 * @date 2023-07-20
 */
@Service
public class MdCategoryTreeServiceImpl {
    @Autowired
    private MdCategoryTreeMapper mdCategoryTreeMapper;

    /**
     * 查询物料产品分类
     *
     * @param id 物料产品分类主键
     * @return 物料产品分类
     */

    public MdCategoryTree selectMdCategoryTreeById(Long id) {
        return mdCategoryTreeMapper.selectMdCategoryTreeById(id);
    }

    /**
     * 查询物料产品分类列表
     *
     * @param mdCategoryTree 物料产品分类
     * @return 物料产品分类
     */

    public List<MdCategoryTree> selectMdCategoryTreeList(MdCategoryTree mdCategoryTree) {
        return mdCategoryTreeMapper.selectMdCategoryTreeList(mdCategoryTree);
    }

    /**
     * 新增物料产品分类
     *
     * @param mdCategoryTree 物料产品分类
     * @return 结果
     */

    public int insertMdCategoryTree(MdCategoryTree mdCategoryTree) {
        mdCategoryTree.setCreateTime(DateUtils.getNowDate());
        MdCategoryTree parentTree = mdCategoryTreeMapper.selectMdCategoryTreeById(mdCategoryTree.getParentId());
        if (parentTree == null | parentTree.getEnableFlag().equals("1")) {
            return 0;
        }
        mdCategoryTree.setAncestors(parentTree.getAncestors() + mdCategoryTree.getParentId() + ",");
        return mdCategoryTreeMapper.insertMdCategoryTree(mdCategoryTree);
    }

    /**
     * 修改物料产品分类
     *
     * @param mdCategoryTree 物料产品分类
     * @return 结果
     */

    public int updateMdCategoryTree(MdCategoryTree mdCategoryTree) {
        mdCategoryTree.setUpdateTime(DateUtils.getNowDate());
        return mdCategoryTreeMapper.updateMdCategoryTree(mdCategoryTree);
    }

    /**
     * 批量删除物料产品分类
     *
     * @param ids 需要删除的物料产品分类主键
     * @return 结果
     */

    public int deleteMdCategoryTreeByIds(Long[] ids) {
        return mdCategoryTreeMapper.deleteMdCategoryTreeByIds(ids);
    }

    /**
     * 删除物料产品分类信息
     *
     * @param id 物料产品分类主键
     * @return 结果
     */

    public int deleteMdCategoryTreeById(Long id) {
        return mdCategoryTreeMapper.deleteMdCategoryTreeById(id);
    }
}